package com.hay.oss.obs;

import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * obs配置
 * @author LiMouRen
 * @date 2023/7/26
 */
@Configuration
@EnableConfigurationProperties({ObsProperties.class})
@ConditionalOnProperty(name = "obs.enable",havingValue = "true")
public class ObsConfig {

    @Bean
    public ObsTemplate obsTemplate(ObsProperties obsProperties) {
        ObsConfiguration config = new ObsConfiguration();
        config.setSocketTimeout(30000);
        config.setConnectionTimeout(10000);
        config.setEndPoint(obsProperties.getEndpoint());
        ObsClient obsClient = new ObsClient(obsProperties.getAccessKey(), obsProperties.getSecretKey(), config);
        return new ObsTemplate(obsProperties,obsClient);
    }

}
